import java.util.Random;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import pack1.Class3;
import pack2.*;

/**
 * Created with IntelliJ IDEA
 * Description:生产者消费者模型
 * User:恋恋
 * Date:2023-01-04
 * Time:15:27
 */

public class ThreadTest {
    public static void main(String[] args) {
        BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<Integer>();
        pack1.Class3 class3 = new Class3();
        pack2.Class3 class31 = new pack2.Class3();

        Thread customer = new Thread(()->{
            while(true){
                try {
                    int value = blockingDeque.take();
                    System.out.println();
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        },"消费者");
        customer.start();

        Thread producer =  new Thread(()->{
            Random random = new Random();
            while(true){
                int num = random.nextInt(100);
                try {
                    blockingDeque.put(num);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"生产者");
        producer.start();

        try {
            producer.join();;
            customer.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ;

    }

}
